package cn.fighter3.controller;


import cn.fighter3.core.CoreProcessor;
import cn.fighter3.entity.node.*;
import cn.fighter3.result.Result;
import cn.fighter3.service.QuestionRepository;
import cn.fighter3.service.impl.BookService;
import cn.fighter3.service.impl.PeopleService;
import cn.fighter3.service.node.*;
import org.neo4j.driver.*;
import org.neo4j.driver.types.Node;
import org.neo4j.driver.types.Path;
import org.neo4j.driver.types.Relationship;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import spire.math.Algebraic;

import java.util.*;

@RestController
@RequestMapping("/api/spark")
public class sparkController {

    @Autowired
    CnbookDao cnbookDao;
    @Autowired
    FgbookDao fgbookDao;
    @Autowired
    MscbookDao mscbookDao;
    @Autowired
    MulbookDao mulbookDao;
    @Autowired
    PapbookDao papbookDao;
    @Autowired
    PerbookDao perbookDao;
    @Autowired
    PeopleDao peopleDao;

    Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("neo4j", "neo4j123"));
    private Session session=driver.session();

    @GetMapping("/ques")
    public void answerSpark() throws Exception {
        CoreProcessor query = new CoreProcessor("D:/JavaProjects/HanLP/data");  //D:\JavaProjects\HanLP\data\question
        String[] questionArr = new String[] {"吕飞写过哪些书"};
        for(String que: questionArr){
            List<String> question = query.analysis(que);
            System.err.println(question);
        }
    }

    @Autowired
    QuestionRepository questionRepository;
    @Autowired
    CoreProcessor queryProcessor;

    @Autowired
    PeopleService peopleService;

    @Autowired
    BookService bookService;


    @GetMapping("/ques1/{ques}")
    public Result answer1(@PathVariable("ques") String ques) throws Exception{
        System.out.println("ques:"+ques);
        List<String> reStrings = queryProcessor.analysis(ques);
        int len=reStrings.size();
        System.out.println(reStrings);
        System.out.println(reStrings.get(len-1));
        int modelIndex = Integer.valueOf(reStrings.get(0));
        String title;
        String name;
        Object obj = null;
        String msg="";
        //Result result = new Result(200,"spark",obj);
        switch (modelIndex){
            case 13:
                obj= getBook1(reStrings);
                msg="13/";
                msg+=reStrings.get(len-1);
                break;
            case 14:
//                title=reStrings.get(1);
//                List<People> peopleList=questionRepository.getAuthor(title);
//                List<CustomNode> customNodes= new ArrayList<>();
//                for (People people:peopleList){
//                    customNodes.add(new CustomNode(people.getAuthorName(),1,people));
//                }
//                obj=customNodes;
                obj=getAuthor1(reStrings);
                msg="14/";
                msg+=reStrings.get(len-1);
                break;
            case 15:
                title=reStrings.get(1);
                obj=questionRepository.getYear(title);
                msg="15/";
                msg+=reStrings.get(len-1);
                break;
            case 16:
                title=reStrings.get(1);
                obj=questionRepository.getPublisher(title);
                msg="16/";
                msg+=reStrings.get(len-1);
                break;
            case 17:
                title=reStrings.get(1);
                obj=questionRepository.getClass1(title);
                msg="17/";
                msg+=reStrings.get(len-1);
                break;
            case 18:
                obj=getBooks11(reStrings);
                msg="18/";
                msg+=reStrings.get(len-1);
                break;
            case 19:
                obj=getBooks21(reStrings);
                msg="19/";
                msg+=reStrings.get(len-1);
                break;
            case 20:
                name=reStrings.get(1);
                obj=questionRepository.getBookcount(name);
                msg="20/";
                msg+=reStrings.get(len-1);
                break;
            case 21:
                name=reStrings.get(1);
                obj=questionRepository.getClass2(name);
                msg="21/";
                msg+=reStrings.get(len-1);
                break;
            case 22:
                obj= getlentBook(reStrings);
                msg="22/";
                msg+=reStrings.get(len-1);
                break;
            case 23:
                obj=getReader1(reStrings);
                msg="23/";
                msg+=reStrings.get(len-1);
                break;
            case 24:
                name=reStrings.get(1);
                title=reStrings.get(2);
                System.out.println("name+title"+name+"  "+title);
                obj=questionRepository.getTime(name,title);
                msg="24/";
                msg+=reStrings.get(len-1);
                break;
            default:
                break;
        }
        return new Result(200,msg,obj);
    }

    //问题13
    public List<CustomNode> getBook1(List<String> reStrings1){
        List<CustomNode> customNodes=new ArrayList<>();
        try {
            String name;
            name = reStrings1.get(1);
            String cql1 = "match (n)-[r:Authorof]->(b:People) where b.authorName='";
            cql1 += name;
            cql1 += "' return n,b";
            String cql2 = cql1.replace('<', '[');
            String cql3 = cql2.replace('&', ']');
            System.out.println("cyther语句：" + cql3);

            org.neo4j.driver.Result result = session.run(cql3);
            Map<Long,String> nodeIds=new HashMap<Long, String>();
            Map<Long,String> relationIds=new HashMap<Long, String>();

            while (result.hasNext()){
                Record record=result.next();
                List<Value> values=record.values();
                for (Value value:values){
                    //System.out.println(value.type().name());
                    if("NODE".equals(value.type().name())) {
                        Node node = value.asNode();
                        if (!nodeIds.containsKey(node.id())) {
                            nodeIds.put(node.id(),"");
                            //System.out.println("nameeeee");
                            if (node.labels().toString().equals("[People]")) {
                                String authorid = node.get("authorId").asString();
                                People people=peopleService.findByAuthorId(authorid).get();
                                CustomNode customNode = new CustomNode(node.get("authorName").asString(), 1, people,0);//peopleDao.countpeo(people.getAuthorId())
                                customNodes.add(customNode);
                                //System.out.println(node.get("authorId").asString());
                                //System.out.println(node.get("authorName").asString());
                            } else if (node.labels().toString().equals("[Cnbook]")) {
                                String bookid = node.get("bookId").asString();
                                Cnbook cnbook= bookService.findByBookId1(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 2, cnbook,0);//cnbookDao.countcn(cnbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Fgbook]")) {
                                String bookid = node.get("bookId").asString();
                                Fgbook fgbook=bookService.findByBookId2(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 3, fgbook,0);//fgbookDao.countfg(fgbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mscbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mscbook mscbook=bookService.findByBookId3(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 4, mscbook,0);//mscbookDao.countmsc(mscbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mulbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mulbook mulbook=bookService.findByBookId4(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 5, mulbook,0);//mulbookDao.countmul(mulbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Papbook]")) {
                                String bookid = node.get("bookId").asString();
                                Papbook papbook=bookService.findByBookId5(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 6, papbook,0);//papbookDao.countpap(papbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Perbook]")) {
                                String bookid = node.get("bookId").asString();
                                Perbook perbook=bookService.findByBookId6(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 7, perbook,0);//perbookDao.countper(perbook.getBookId())
                                customNodes.add(customNode);
                            }
                        }
                    }
                }
            }
        }catch (Exception e) {
            System.out.println("error");
            System.out.println(e.getClass() + "," + e.getMessage());
        }
        return customNodes;
    }


    //问题14
    public List<CustomNode> getAuthor1(List<String> reStrings1){
        List<CustomNode> customNodes=new ArrayList<>();
        try {
            String name;
            name = reStrings1.get(1);
            String cql1 = "match (n)-[r:Authorof]->(b:People) where n.title='";
            cql1 += name;
            cql1 += "' return n,b";
            String cql2 = cql1.replace('<', '[');
            String cql3 = cql2.replace('&', ']');
            System.out.println("cyther语句：" + cql3);

            org.neo4j.driver.Result result = session.run(cql3);
            Map<Long,String> nodeIds=new HashMap<Long, String>();
            Map<Long,String> relationIds=new HashMap<Long, String>();

            while (result.hasNext()){
                Record record=result.next();
                List<Value> values=record.values();
                for (Value value:values){
                    //System.out.println(value.type().name());
                    if("NODE".equals(value.type().name())) {
                        Node node = value.asNode();
                        if (!nodeIds.containsKey(node.id())) {
                            nodeIds.put(node.id(),"");
                            //System.out.println("nameeeee");
                            if (node.labels().toString().equals("[People]")) {
                                String authorid = node.get("authorId").asString();
                                People people=peopleService.findByAuthorId(authorid).get();
                                CustomNode customNode = new CustomNode(node.get("authorName").asString(), 1, people,0);//peopleDao.countpeo(people.getAuthorId())
                                customNodes.add(customNode);
                                //System.out.println(node.get("authorId").asString());
                                //System.out.println(node.get("authorName").asString());
                            } else if (node.labels().toString().equals("[Cnbook]")) {
                                String bookid = node.get("bookId").asString();
                                Cnbook cnbook= bookService.findByBookId1(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 2, cnbook,0);//cnbookDao.countcn(cnbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Fgbook]")) {
                                String bookid = node.get("bookId").asString();
                                Fgbook fgbook=bookService.findByBookId2(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 3, fgbook,0);//fgbookDao.countfg(fgbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mscbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mscbook mscbook=bookService.findByBookId3(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 4, mscbook,0);//mscbookDao.countmsc(mscbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mulbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mulbook mulbook=bookService.findByBookId4(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 5, mulbook,0);//mulbookDao.countmul(mulbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Papbook]")) {
                                String bookid = node.get("bookId").asString();
                                Papbook papbook=bookService.findByBookId5(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 6, papbook,0);//papbookDao.countpap(papbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Perbook]")) {
                                String bookid = node.get("bookId").asString();
                                Perbook perbook=bookService.findByBookId6(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 7, perbook,0);//perbookDao.countper(perbook.getBookId())
                                customNodes.add(customNode);
                            }
                        }
                    }
                }
            }
        }catch (Exception e) {
            System.out.println("error");
            System.out.println(e.getClass() + "," + e.getMessage());
        }
        return customNodes;
    }


//问题18
    public List<CustomNode> getBooks11(List<String> reStrings1){
        List<CustomNode> customNodes=new ArrayList<>();
        try {
            String publisher;
            publisher = reStrings1.get(1);
            String cql1 = "match (n) where n.M_PUBLISHER='";
            cql1 += publisher;
            cql1 += "' return n limit 10";
            String cql2 = cql1.replace('<', '[');
            String cql3 = cql2.replace('&', ']');
            System.out.println("cyther语句：" + cql3);

            org.neo4j.driver.Result result = session.run(cql3);
            Map<Long,String> nodeIds=new HashMap<Long, String>();
            Map<Long,String> relationIds=new HashMap<Long, String>();

            while (result.hasNext()){
                Record record=result.next();
                List<Value> values=record.values();
                for (Value value:values){
                    //System.out.println(value.type().name());
                    if("NODE".equals(value.type().name())) {
                        Node node = value.asNode();
                        if (!nodeIds.containsKey(node.id())) {
                            nodeIds.put(node.id(),"");
                            //System.out.println("nameeeee");
                            if (node.labels().toString().equals("[People]")) {
                                String authorid = node.get("authorId").asString();
                                People people=peopleService.findByAuthorId(authorid).get();
                                CustomNode customNode = new CustomNode(node.get("authorName").asString(), 1, people,0);//peopleDao.countpeo(people.getAuthorId())
                                customNodes.add(customNode);
                                //System.out.println(node.get("authorId").asString());
                                //System.out.println(node.get("authorName").asString());
                            } else if (node.labels().toString().equals("[Cnbook]")) {
                                String bookid = node.get("bookId").asString();
                                Cnbook cnbook= bookService.findByBookId1(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 2, cnbook,0);//cnbookDao.countcn(cnbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Fgbook]")) {
                                String bookid = node.get("bookId").asString();
                                Fgbook fgbook=bookService.findByBookId2(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 3, fgbook,0);//fgbookDao.countfg(fgbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mscbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mscbook mscbook=bookService.findByBookId3(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 4, mscbook,0);//mscbookDao.countmsc(mscbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mulbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mulbook mulbook=bookService.findByBookId4(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 5, mulbook,0);//mulbookDao.countmul(mulbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Papbook]")) {
                                String bookid = node.get("bookId").asString();
                                Papbook papbook=bookService.findByBookId5(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 6, papbook,0);//papbookDao.countpap(papbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Perbook]")) {
                                String bookid = node.get("bookId").asString();
                                Perbook perbook=bookService.findByBookId6(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 7, perbook,0);//perbookDao.countper(perbook.getBookId())
                                customNodes.add(customNode);
                            }
                        }
                    }
                }
            }
        }catch (Exception e) {
            System.out.println("error");
            System.out.println(e.getClass() + "," + e.getMessage());
        }
        return customNodes;
    }



    //问题19
    public List<CustomNode> getBooks21(List<String> reStrings1){
        List<CustomNode> customNodes=new ArrayList<>();
        try {
            String year;
            year = reStrings1.get(1);
            String cql1 = "match (n) where n.M_PUB_YEAR='";
            cql1 += year;
            cql1 += "' return n limit 10";
            String cql2 = cql1.replace('<', '[');
            String cql3 = cql2.replace('&', ']');
            System.out.println("cyther语句：" + cql3);

            org.neo4j.driver.Result result = session.run(cql3);
            Map<Long,String> nodeIds=new HashMap<Long, String>();
            Map<Long,String> relationIds=new HashMap<Long, String>();

            while (result.hasNext()){
                Record record=result.next();
                List<Value> values=record.values();
                for (Value value:values){
                    //System.out.println(value.type().name());
                    if("NODE".equals(value.type().name())) {
                        Node node = value.asNode();
                        if (!nodeIds.containsKey(node.id())) {
                            nodeIds.put(node.id(),"");
                            //System.out.println("nameeeee");
                            if (node.labels().toString().equals("[People]")) {
                                String authorid = node.get("authorId").asString();
                                People people=peopleService.findByAuthorId(authorid).get();
                                CustomNode customNode = new CustomNode(node.get("authorName").asString(), 1, people,0);//peopleDao.countpeo(people.getAuthorId())
                                customNodes.add(customNode);
                                //System.out.println(node.get("authorId").asString());
                                //System.out.println(node.get("authorName").asString());
                            } else if (node.labels().toString().equals("[Cnbook]")) {
                                String bookid = node.get("bookId").asString();
                                Cnbook cnbook= bookService.findByBookId1(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 2, cnbook,0);//cnbookDao.countcn(cnbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Fgbook]")) {
                                String bookid = node.get("bookId").asString();
                                Fgbook fgbook=bookService.findByBookId2(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 3, fgbook,0);//fgbookDao.countfg(fgbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mscbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mscbook mscbook=bookService.findByBookId3(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 4, mscbook,0);//mscbookDao.countmsc(mscbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mulbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mulbook mulbook=bookService.findByBookId4(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 5, mulbook,0);//mulbookDao.countmul(mulbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Papbook]")) {
                                String bookid = node.get("bookId").asString();
                                Papbook papbook=bookService.findByBookId5(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 6, papbook,0);//papbookDao.countpap(papbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Perbook]")) {
                                String bookid = node.get("bookId").asString();
                                Perbook perbook=bookService.findByBookId6(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 7, perbook,0);//perbookDao.countper(perbook.getBookId())
                                customNodes.add(customNode);
                            }
                        }
                    }
                }
            }
        }catch (Exception e) {
            System.out.println("error");
            System.out.println(e.getClass() + "," + e.getMessage());
        }
        return customNodes;
    }

    //问题22
    public List<CustomNode> getlentBook(List<String> reStrings1){
        List<CustomNode> customNodes=new ArrayList<>();
        try {
            String name;
            name = reStrings1.get(1);
            String cql1 = "match(n:People)-[r:Lend]->(b) where n.authorName='";
            cql1 += name;
            cql1 += "' return n,b";
            String cql2 = cql1.replace('<', '[');
            String cql3 = cql2.replace('&', ']');
            System.out.println("cyther语句：" + cql3);

            org.neo4j.driver.Result result = session.run(cql3);
            Map<Long,String> nodeIds=new HashMap<Long, String>();
            Map<Long,String> relationIds=new HashMap<Long, String>();

            while (result.hasNext()){
                Record record=result.next();
                List<Value> values=record.values();
                for (Value value:values){
                    //System.out.println(value.type().name());
                    if("NODE".equals(value.type().name())) {
                        Node node = value.asNode();
                        if (!nodeIds.containsKey(node.id())) {
                            nodeIds.put(node.id(),"");
                            //System.out.println("nameeeee");
                            if (node.labels().toString().equals("[People]")) {
                                String authorid = node.get("authorId").asString();
                                People people=peopleService.findByAuthorId(authorid).get();
                                CustomNode customNode = new CustomNode(node.get("authorName").asString(), 1, people,0);//peopleDao.countpeo(people.getAuthorId())
                                customNodes.add(customNode);
                                //System.out.println(node.get("authorId").asString());
                                //System.out.println(node.get("authorName").asString());
                            } else if (node.labels().toString().equals("[Cnbook]")) {
                                String bookid = node.get("bookId").asString();
                                Cnbook cnbook= bookService.findByBookId1(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 2, cnbook,0);//cnbookDao.countcn(cnbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Fgbook]")) {
                                String bookid = node.get("bookId").asString();
                                Fgbook fgbook=bookService.findByBookId2(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 3, fgbook,0);//fgbookDao.countfg(fgbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mscbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mscbook mscbook=bookService.findByBookId3(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 4, mscbook,0);//mscbookDao.countmsc(mscbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mulbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mulbook mulbook=bookService.findByBookId4(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 5, mulbook,0);//mulbookDao.countmul(mulbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Papbook]")) {
                                String bookid = node.get("bookId").asString();
                                Papbook papbook=bookService.findByBookId5(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 6, papbook,0);//papbookDao.countpap(papbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Perbook]")) {
                                String bookid = node.get("bookId").asString();
                                Perbook perbook=bookService.findByBookId6(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 7, perbook,0);//perbookDao.countper(perbook.getBookId())
                                customNodes.add(customNode);
                            }
                        }
                    }
                }
            }
        }catch (Exception e) {
            System.out.println("error");
            System.out.println(e.getClass() + "," + e.getMessage());
        }
        return customNodes;
    }

    //问题23

    public List<CustomNode> getReader1(List<String> reStrings1){
        List<CustomNode> customNodes=new ArrayList<>();
        try {
            String name;
            name = reStrings1.get(1);
            String cql1 = "match (n:People)-[r:Lend]->(b) where b.title='";
            cql1 += name;
            cql1 += "' return n,b";
            String cql2 = cql1.replace('<', '[');
            String cql3 = cql2.replace('&', ']');
            System.out.println("cyther语句：" + cql3);

            org.neo4j.driver.Result result = session.run(cql3);
            Map<Long,String> nodeIds=new HashMap<Long, String>();
            Map<Long,String> relationIds=new HashMap<Long, String>();

            while (result.hasNext()){
                Record record=result.next();
                List<Value> values=record.values();
                for (Value value:values){
                    //System.out.println(value.type().name());
                    if("NODE".equals(value.type().name())) {
                        Node node = value.asNode();
                        if (!nodeIds.containsKey(node.id())) {
                            nodeIds.put(node.id(),"");
                            //System.out.println("nameeeee");
                            if (node.labels().toString().equals("[People]")) {
                                String authorid = node.get("authorId").asString();
                                People people=peopleService.findByAuthorId(authorid).get();
                                CustomNode customNode = new CustomNode(node.get("authorName").asString(), 1, people,0);//peopleDao.countpeo(people.getAuthorId())
                                customNodes.add(customNode);
                                //System.out.println(node.get("authorId").asString());
                                //System.out.println(node.get("authorName").asString());
                            } else if (node.labels().toString().equals("[Cnbook]")) {
                                String bookid = node.get("bookId").asString();
                                Cnbook cnbook= bookService.findByBookId1(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 2, cnbook,0);//cnbookDao.countcn(cnbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Fgbook]")) {
                                String bookid = node.get("bookId").asString();
                                Fgbook fgbook=bookService.findByBookId2(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 3, fgbook,0);//fgbookDao.countfg(fgbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mscbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mscbook mscbook=bookService.findByBookId3(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 4, mscbook,0);//mscbookDao.countmsc(mscbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Mulbook]")) {
                                String bookid = node.get("bookId").asString();
                                Mulbook mulbook=bookService.findByBookId4(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 5, mulbook,0);//mulbookDao.countmul(mulbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Papbook]")) {
                                String bookid = node.get("bookId").asString();
                                Papbook papbook=bookService.findByBookId5(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 6, papbook,0);//papbookDao.countpap(papbook.getBookId())
                                customNodes.add(customNode);
                            } else if (node.labels().toString().equals("[Perbook]")) {
                                String bookid = node.get("bookId").asString();
                                Perbook perbook=bookService.findByBookId6(bookid);
                                CustomNode customNode = new CustomNode(node.get("title").asString(), 7, perbook,0);//perbookDao.countper(perbook.getBookId())
                                customNodes.add(customNode);
                            }
                        }
                    }
                }
            }
        }catch (Exception e) {
            System.out.println("error");
            System.out.println(e.getClass() + "," + e.getMessage());
        }
        return customNodes;
    }
}
